package com.tedu.weibo.common.result;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "状态码", required = true, example = "2001")
    private Integer status;
    @ApiModelProperty(value = "状态信息", required = true, example = "操作成功")
    private String msg;
    @ApiModelProperty(value = "返回数据", required = true)
    private Object data;

    public JsonResult(StatusCode status) {
        this.status = status.getStatusCode();
        this.msg = status.getMessage();
    }

    public JsonResult(StatusCode status, Object data) {
        this(status);// 调用有参构造器,只能在第一行调用
        this.data = data;
    }

    public static JsonResult success(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }
    public static JsonResult success() {
        return success(null);
    }
}
